class Vue {
  constructor (options) {
    this.$options = options || {}
    this.$data = options.data || {}
    this.$el = typeof options.el === 'string' ? document.querySelector(options.el) : options.el
    // 将vm[key]代理到data对象中
    this._proxyData(this.$data)
    // 将vm[key]代理到methods对象中
    this._proxyData(this.$options.methods)
    new Observer(this.$data)
    new Compiler(this)
  }
  _proxyData (data) {
    Object.keys(data).forEach(key => {
      Object.defineProperty(this, key, {
        enumerable: true,
        configurable: true,
        get () {
          return data[key]
        },
        set (val) {
          if (val === data[key]) return
          data[key] = val
        }
      })
    })
  }
}